package com.stm.web.controller.basicData;

import java.util.List;

import com.stm.basicData.domain.ToolsFactory;
import com.stm.basicData.service.IToolsFactoryService;
import com.stm.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.stm.common.annotation.Log;
import com.stm.common.enums.BusinessType;
import com.stm.basicData.domain.FactoryLinkman;
import com.stm.basicData.service.IFactoryLinkmanService;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.utils.poi.ExcelUtil;

/**
 * 厂家联系人 信息操作处理
 * 
 * @author wyc
 * @date 2019-04-08
 */
@Controller
@RequestMapping("/basicData/factoryLinkman")
public class FactoryLinkmanController extends BaseController
{
    private String prefix = "basicData/factoryLinkman";
	
	@Autowired
	private IFactoryLinkmanService factoryLinkmanService;

	@Autowired
	private IToolsFactoryService toolsFactoryService;

	@RequiresPermissions("basicData:factoryLinkman:view")
	@GetMapping()
	public String factoryLinkman()
	{
	    return prefix + "/factoryLinkman";
	}
	
	/**
	 * 查询厂家联系人列表
	 */
	@RequiresPermissions("basicData:factoryLinkman:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list( String factoryIds , FactoryLinkman factoryLinkman)
	{
		startPage();
		factoryLinkman.setFactoryId(factoryIds);
        List<FactoryLinkman> list = factoryLinkmanService.selectFactoryLinkmanList(factoryLinkman);
		return getDataTable(list);
	}

	/**
	 * 初始化下拉列表数据
	 * 查询出所有厂家
	 */
	@PostMapping("/initFactoryList")
	@ResponseBody
	public List<ToolsFactory> initFactoryList(ToolsFactory toolsFactory)
	{
		return  toolsFactoryService.selectToolsFactoryList(toolsFactory);
	}

	/**
	 * 导出厂家联系人列表
	 */
	@RequiresPermissions("basicData:factoryLinkman:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FactoryLinkman factoryLinkman)
    {
    	List<FactoryLinkman> list = factoryLinkmanService.selectFactoryLinkmanList(factoryLinkman);
        ExcelUtil<FactoryLinkman> util = new ExcelUtil<FactoryLinkman>(FactoryLinkman.class);
        return util.exportExcel(list, "factoryLinkman");
    }
	
	/**
	 * 新增厂家联系人
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存厂家联系人
	 */
	@RequiresPermissions("basicData:factoryLinkman:add")
	@Log(title = "厂家联系人", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FactoryLinkman factoryLinkman)
	{
		factoryLinkman.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		factoryLinkman.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(factoryLinkmanService.insertFactoryLinkman(factoryLinkman));
	}

	/**
	 * 修改厂家联系人
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		FactoryLinkman factoryLinkman = factoryLinkmanService.selectFactoryLinkmanById(id);
		mmap.put("factoryLinkman", factoryLinkman);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存厂家联系人
	 */
	@RequiresPermissions("basicData:factoryLinkman:edit")
	@Log(title = "厂家联系人", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FactoryLinkman factoryLinkman)
	{
		factoryLinkman.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(factoryLinkmanService.updateFactoryLinkman(factoryLinkman));
	}
	
	/**
	 * 删除厂家联系人
	 */
	@RequiresPermissions("basicData:factoryLinkman:remove")
	@Log(title = "厂家联系人", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(factoryLinkmanService.deleteFactoryLinkmanByIds(ids));
	}
	
}
